#ifndef TICKETSSIDEBAR_H
#define TICKETSSIDEBAR_H

#include <QtCore/QUrl>
#include <QtGui/QMenu>
#include <QtGui/QWidget>

namespace Ui {
    class TicketsSideBar;
}


class QAbstractItemModel;
class QSortFilterProxyModel;
class QLineEdit;
class SearchWidget;
class BaseTicketItemModel;
class InformationWidget;
class TicketError;
class ITicketBackendConfiguration;
class SingleTicketWidget;

namespace ProjectExplorer {
class Project;
}

class TicketsSideBarPrivate;
class TicketsSideBar : public QWidget
{
    Q_OBJECT

public:
    explicit TicketsSideBar(QWidget *parent = 0);
    ~TicketsSideBar();
    void saveSettings();
    void restoreSettings();

private slots:
    void search();
    void openCurrentTicket();
    void queryComplete(int done, int total);
    void fieldsUpdated();
    void onError(const TicketError &error);
    void openHeaderContextMenu(QPoint);
    void menuCheckBoxIsVisible_toggled(bool isChecked);
    void projectChanged(ProjectExplorer::Project *project);
    void on_buttonNewTicket_clicked();

private:
    void changeConfiguration(ITicketBackendConfiguration *conf);
    void setTicketModel(BaseTicketItemModel *model);
    QUrl currentConfiguredUrl(ProjectExplorer::Project *project);

    Ui::TicketsSideBar *ui;
    TicketsSideBarPrivate *d;

    SearchWidget *m_searchWidget;
    QSortFilterProxyModel *m_proxy;
    QMenu *m_ticketsViewHeaderMenu;
    InformationWidget *m_infoWidget;
    SingleTicketWidget *m_ticketWindow;

    // XXX: Get rid of these two once the backend is properly loaded
    ProjectExplorer::Project *m_project;
    QUrl m_currentBackendUrl;
};

class QLineEdit;
class QPushButton;
class QToolButton;
class QComboBox;
class TicketQuery;

class SearchWidget : public QWidget {
    Q_OBJECT
public:
    SearchWidget(QWidget *parent = 0);

    TicketQuery query() const;
signals:
    void search();

public slots:
    void fieldUpdated(const QStringList &types, const QStringList &statuses);

private slots:
    void advancedButtonClicked();
    void closedTicketsToggled(bool showClosed);

private:
    QStringList m_statuses;
    bool m_simpleSearch;
    bool m_showClosed;
    QLineEdit *m_searchEdit;
    QPushButton *m_searchButton;
    QToolButton *m_advancedSearchButton;
    QWidget *m_advancedSearchWidget;
    QComboBox *m_typesCombo;
    QLineEdit *m_summaryEdit;
    QLineEdit *m_descriptionEdit;
    QLineEdit *m_ownerEdit;
};

#endif // TICKETSSIDEBAR_H
